<?php
/**
 * Created by YuanXiShop.
 * User: YuanXi
 * Date: 2021/6/2 0002
 * Time: 21:05
 */

namespace admin;

use models\BaseDao;

class Index extends Admin
{
    function __construct()
    {
        // $this->assign('menumark','index');
        parent::__construct();
    }

    function index(){
        $this->assign("title", "后台首页");

        $db = new BaseDao();
        // 商品的统计
        $tongji = [];
        // 上架的商品
        $tongji['product_up'] = $db->count('product', ['state'=>1]);
        // 下架的商品
        $tongji['product_down'] = $db->count('product', ['state'=>0]);
        // 缺货的商品
        $tongji['product_empty'] = $db->count('product', ['num[<]'=>1]);
        // 推荐的商品
        $tongji['product_tuijian'] = $db->count('product', ['state'=>1,'istuijian'=>1]);
        // 访客统计
        $today = strtotime(date('Y-m-d'));
        $yesterday = strtotime(date('Y-m-d',strtotime('-1 day')));

        // 今日访客
        $tongji['iplog_today']=$db->count('iplog',['atime[>=]'=>$today]);

        // 昨日访客
        $tongji['iplog_lastday']=$db->count('iplog',['atime[>=]'=>$yesterday,'atime[<=]'=>$today]);

        // 累计的访客
        $tongji['iplog_all']=$db->count('iplog');

        // 所有注册
        $tongji['iplog_user']=$db->count('user');

        // 交易数据

        // 今日定单
        $tongji['order_today']=$db->count('order',['atime[>=]'=>$today]);
        $money_today = $db->sum('order','productmoney',['atime[>=]'=>$today]);
        $tongji['money_today']=number_format($money_today,2,'.','');
        // 昨日定单
        $tongji['order_lastday']=$db->count('order',['atime[>=]'=>$yesterday,'atime[<=]'=>$today]);
        $money_lastday = $db->sum('order','productmoney',['atime[>=]'=>$today]);
        $tongji['money_lastday']=number_format($money_lastday,2,'.','');

        // 全部定单
        $tongji['order_all']=$db->count('order');
        $money_all = $db->sum('order','productmoney');
        $tongji['money_all']=number_format($money_all,2,'.','');



        $this->assign($tongji);
        $this->display('index/index');
    }
}